//
//  NSUserDefaults+UnRegisterDefault.m
//  mmbang
//
//  Created by CuiPanJun on 14-8-11.
//  Copyright (c) 2014年 iyaya. All rights reserved.
//

#import "NSUserDefaults+UnRegisterDefault.h"

@implementation NSUserDefaults (UnRegisterDefault)


- (void)unregisterDefaultForKey:(NSString *)defaultName {
    NSDictionary *registeredDefaults = [[NSUserDefaults standardUserDefaults] volatileDomainForName:NSRegistrationDomain];
    if ([registeredDefaults objectForKey:defaultName] != nil) {
        NSMutableDictionary *mutableCopy = [NSMutableDictionary dictionaryWithDictionary:registeredDefaults];
        [mutableCopy removeObjectForKey:defaultName];
        [self replaceRegisteredDefaults:[mutableCopy copy]];
    }
}

- (void)replaceRegisteredDefaults:(NSDictionary *)dictionary {
    [[NSUserDefaults standardUserDefaults] setVolatileDomain:dictionary forName:NSRegistrationDomain];
}

@end
